package cn.dzhang.spring.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import cn.dzhang.spring.model.Account;
import cn.dzhang.spring.repository.AccountRepository;
import cn.dzhang.spring.service.AccountService;

@Service("accountService")
public class AccountServiceImpl implements AccountService {
	@Resource
	private AccountRepository repository;

	@Override
	public Account saveOrUpdate(Account account) {
		return repository.saveAndFlush(account);
	}

	@Override
	public boolean deleteById(String id) {
		try {
			repository.delete(id);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	@Override
	public List<Account> findAll() {
		return repository.findAll(new Sort("name"));
	}

	@Override
	public Account findById(String id) {
		return repository.findOne(id);
	}
}
